home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / develop / libsrc11.arc / ERBLKEE.C < prev    next >
C/C++ Source or Header  |  1989-04-27  |  2KB  |  85 lines

  1. /*    erblkee.c 4.4        */
  2. /*F********************************************************************
  3.  
  4. FUNCTION NAME:    erblkee
  5.  
  6. ACTION:     Erase mulitple bytes in EEPROM.  This routine will
  7.         erase as much as possible in a single operation.
  8.         If a "bulk" erase can be done, then it is done. 
  9.         If bulk is not done, row erases are done when possible.
  10.         Otherwise byte erases are done.    
  11.  
  12. PARAMETERS:
  13.         addr:    location of EEPROM to be erased. -1 indicates
  14.             to erase the config register.
  15.  
  16.         count:    number of bytes to erase.
  17.  
  18. **********************************************************************/
  19.  
  20.  
  21. #define    EROM_SIZE    512    /* Size of EEPROM */
  22. #define    ERASE_TIME    10    /* number of milliseconds to delay for erase */
  23. #define ERASE_CONFIG    -1    /* erase config register indicator */
  24. #define    ROWSIZE        16    /* row size */
  25.  
  26. #include <hc11/io.h>
  27. #include <hc11/config.h>
  28. #include <hc11/directives.h>
  29.  
  30. SMALL
  31. int erblkee(addr, count)
  32.  
  33.     int    addr;        /* location(s) to be erased */
  34.     int    count;        /* number of bytes to be erased */
  35.  
  36.     {
  37.  
  38.     if (((count+addr)>EROM_SIZE)||(addr<ERASE_CONFIG)||(addr>=EROM_SIZE))
  39.         return(-1);
  40.  
  41.     if (((count+addr)==EROM_SIZE) && (addr<=0))
  42.         {    /* erase all of EEPROM and maybe config */
  43.  
  44.         HC11.PPROG = EELAT | ERASE;
  45.  
  46.         if (addr == ERASE_CONFIG)    /* erase config register ? */
  47.            HC11.CONFIG = 0;
  48.         else
  49.            EEPROM[0] = 0;
  50.  
  51.         HC11.PPROG = EELAT | ERASE | EEPGM | EEBLK;
  52.  
  53.         /* delay 10 milliseconds */
  54.         delay(ERASE_TIME);
  55.  
  56.         HC11.PPROG = EELAT | ERASE;
  57.  
  58.         HC11.PPROG = 0;    /* enable reads of EEPROM */
  59.  
  60.         }
  61.  
  62.     else    /* erase part of EEPROM */
  63.         {
  64.  
  65.         while (count > 0)
  66.            {
  67.            if ((count>=ROWSIZE) && ((addr&(ROWSIZE-1)) == 0))
  68.  
  69.             {    /* erase row */
  70.             errowee(addr);
  71.             count -= ROWSIZE;
  72.                 addr += ROWSIZE;
  73.             }
  74.            else
  75.             {    /* erase byte */
  76.             count--;
  77.             erbytee(addr++);
  78.             }
  79.            }    /* end of while bytes to erase... */
  80.         }    /* end of erase part of EEPROM */
  81.  
  82.     return(0);    /* good exit... */
  83.  
  84.     }    /* end of erblkee */
  85.